﻿@model EquipmentStockLogListModel
@using Nop.Core.Domain.XJ

@Html.ValidationSummary(false)

<div class="content" style="padding-top:0;">
    <div class="form-horizontal">
        <div class="panel-group">
            <div class="panel panel-default">
                <div class="panel-body">
                    @{
                        var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
                        var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;
                    }


                    <div id="logs-grid"></div>
                    <input type="submit" id="btnRefreshLogs" style="display: none" />

                    <script>
                        $(document).ready(function() {
                            $("#logs-grid").kendoGrid({
                                dataSource: {
                                    type: "json",
                                    transport: {
                                        read: {
                                            url: "@Html.Raw(Url.Action("List", "EquipmentStockLog", new { SearchEquipmentId = Model.SearchEquipmentId }))",
                                            type: "POST",
                                            dataType: "json",
                                            data: addAntiForgeryToken
                                        }
                                    },
                                    schema: {
                                        data: "Data",
                                        total: "Total",
                                        errors: "Errors",
                                        model: {
                                            id: "Id",
                                            fields: {
                                                EquipmentName: { editable: false, type: "string" },
                                                Manufacturer: { editable: false, type: "string" },
                                                Specification: { editable: false, type: "string" },
                                                CreatedOn: { editable: false, type: "date" },
                                                Price: { editable: false, type: "number" },
                                                Amount: { editable: false, type: "number" },
                                                Id: { editable: false, type: "number" }
                                            }
                                        }
                                    },
                                    requestEnd: function (e) {
                                        if (e.type == "read") {
                                            var response = e.response;
                                            if (response) {
                                                //store extra data
                                                reportAggregates = e.response["ExtraData"];
                                            }
                                        }
                                        if (e.type == "update") {
                                            this.read();
                                        }
                                    },
                                    error: function(e) {
                                        display_kendoui_grid_error(e);
                                        // Cancel the changes
                                        this.cancelChanges();
                                    },
                                    pageSize: @(defaultGridPageSize),
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                pageable: {
                                    refresh: true,
                                    pageSizes: [@(gridPageSizes)],
                                    @Html.Partial("_GridPagerMessages")
                                },
                                editable: {
                                    confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                    mode: "inline"
                                },
                                scrollable: false,
                                dataBound: onDataBound,
                                columns: [
                                    {
                                        field: "Name",
                                        title: "名称",
                                        width: 200,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                    }, {
                                        field: "Manufacturer",
                                        title: "品牌",
                                        width: 200,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                    }, {
                                        field: "Specification",
                                        title: "规格型号",
                                        width: 200,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                    },{
                                        field: "Price",
                                        title: "价格",
                                        width: 100,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:right" },
                                        format: "{0:N2}",
                                        footerTemplate: '<div style="text-align:right;">@T("Admin.Orders.Report.Total")：</div>',
                                    },{
                                        field: "Amount",
                                        title: "数量",
                                        width: 100,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:right" },
                                        template: '# if(RelatedType==@((int)StockRelatedTypeEnum.入库)) {# <span style="color:blue;">+#=Amount##=Unit#</span> #} else {# <span style="color:red;">-#=Amount##=Unit#</span> #} #',
                                        footerTemplate: '<div style="text-align:right;"><span id=\"aggregator-total-amount\"></span></div>'
                                    }, {
                                        field: "Comment",
                                        title: "备注",
                                        width: 200,
                                        headerAttributes: { style: "text-align:center" },
                                    }, {
                                        field: "DepartmentName",
                                        title: "操作部门",
                                        width: 150,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                    }, {
                                        field: "CustomerName",
                                        title: "操作人",
                                        width: 80,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                    }, {
                                        field: "CreatedOn",
                                        title: "操作时间",
                                        width: 100,
                                        type: "date",
                                        format: "{0:yyyy/MM/dd}",
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                    },
                                ],
                            });
                            $('#btnRefreshLogs').click(function () {
                                //refresh grid
                                var grid = $("#logs-grid").data('kendoGrid');
                                grid.dataSource.read();

                                //return false to don't reload a page
                                return false;
                            });
                        });

                        function onDataBound(e) {
                            //update order totals summary
                            if (reportAggregates != "") {
                                for (var key in reportAggregates) {
                                    $('#aggregator-total-amount').text(reportAggregates['Amount']);
                                }
                            }
                        }
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
